package fr.afcepf.atod19.dreamproject.service.implementation;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

import fr.afcepf.atod19.dreamproject.business.model.EntityIntervention;
import fr.afcepf.atod19.dreamproject.business.model.Intervention;
import fr.afcepf.atod19.dreamproject.business.orchestration.IOrchestration;
import fr.afcepf.atod19.dreamproject.business.orchestration.OrchestrationImpl;
import fr.afcepf.atod19.dreamproject.service.interfaces.IAppelWebService;

import java.util.Date;
import java.util.List;

@Path("/webservice")
public class AppelWebServiceImpl implements IAppelWebService {
    private IOrchestration webService;

	@Override
	@Path("/addIntervention")
    @POST
    @Produces(MediaType.TEXT_PLAIN)
	public String addInterventionBrigade(
            @FormParam("idReve") int idReve,
            @FormParam("adresseClient") String adresseClient,
			@FormParam("nomClient") String nomClient,
            @FormParam("prenomClient") String prenomClient) {
		String retour = webService.addInterventionBrigade(idReve, adresseClient, nomClient, prenomClient);
        return retour;
	}

	@Override
	@Path("/getInterventions/{idReve}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
	public Intervention getInterventionByIdReve(@PathParam("idReve") int idReve) {
		Intervention retour = webService.getInterventionByIdReve(idReve);
		return retour;
	}


	@Override
	@Path("/sendCommande")
    @POST
    @Produces(MediaType.APPLICATION_JSON)
	public String sendExpedtion(@FormParam("adrFacturation") String adrFacturation, @FormParam("adrLivraison") String adrLivraison) {
//		String date = (new Date()).toString().replace("/", "_");
		String date = "29_08_2014";
		String retour = webService.sendExpedtion(27, date, adrFacturation, adrLivraison);
		return retour;
	}

	public IOrchestration getWebService() {
		return webService;
	}

	public void setWebService(IOrchestration webService) {
		this.webService = webService;
	}


	//********************************************************************
	//********************************************************************
    @Path("/getTest")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String getTestOrchestration() {
        Intervention retour = webService.TestAppelWS(1);
        System.out.println(retour);
        return retour.toString();
    }

    @Override
    @Path("/addIntervention/{idReve}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String addIntervention(@PathParam("idReve") int idReve) {
		String retour = "\"idReve\" : "+ idReve+", \"listInter\":[{\"date\":\"21/03/1989\", \"commentaire\":\"mwouhahah\"},{\"date\":\"05/08/1985\", \"commentaire\":\"hihihihihihi\"}]";
		return retour;
	}
	//********************************************************************
	//********************************************************************


    @Override
    @Path("/getAllInterventions")
    @GET
    @Produces("application/json;charset=utf-8")
    public List<EntityIntervention> getAllInterventions() {
        List<EntityIntervention> interventions = webService.getAllInterventions();
        System.out.println("interventions = " + interventions);
        return interventions;
    }
}
